package demo2;

import java.util.Objects;

class Person {
    public String name;
    public int age;

    public Person() {}
    public Person(String name, int age) {
        this.name=name;
        this.age=age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age && Objects.equals(name, person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}



public class Test {
    public static void main(String[] args) {
        Person p1=new Person("zhangshan",18);
        Person p2=new Person("zhangshan",18);

        System.out.println(p1);
        System.out.println(p2);

        System.out.println(p1.equals(p2));
    }
}
